#ifndef SGU_ZSTRING_H
#define SGU_ZSTRING_H

SGU_NS_BEGIN

size_t utobase(unsigned int n, char *, int base, size_t minwidth=0);

template <typename T> size_t utod(T n, char * str)
{
	return utobase((unsigned int)n,str,10);
}
	
template <typename T> size_t utob(T n, char * str)
{
	*str = '%';
	return utobase((unsigned int)n,str+1,2,sizeof(n)*CHAR_BIT);
}

template <typename T> size_t utox(T n, char * str)
{
	*str = '$';
	return utobase((unsigned int)n,str+1,16,sizeof(n)*CHAR_BIT/4);
}

template <typename T> size_t utoo(T n, char * str)
{
	return utobase((unsigned int)n,str,8);
}

size_t itod(int n, char * str, bool plus = false);
size_t rtos(real, char *);
void trim(char *, const char * pattern = " \t\r\n");
real stor(const char *);
std::string ptoa(const void *);

void strupr(char *);
void strlwr(char *);
void makeupper(std::string &);
void makelower(std::string &);
std::string toupper(const std::string &);                   
std::string tolower(const std::string &);                   

std::string rjus(const std::string &, size_t totalsize, char pad = ' '); 
std::string ljus(const std::string &, size_t totalsize, char pad = ' '); 

std::string format(const char * pattern, const std::vector<std::string> &);

std::string itod(int);
std::string rtos(real);
std::string trim(const std::string &, const char * pattern = " \t\r\n");

unsigned int stou(const char * str, char ** endptr);

std::vector<std::string> parse(
	const std::string & str,
	bool usespc,
	const std::string & tok,
	bool toka,
	char sdl,
	bool sdla,
	char bsl,
	char com
	);


class Format
{
	protected:
	std::string _form;
	std::vector<std::string> _data;
	
	public:
	Format(const char *);
	Format(const std::string &);
	Format & operator % (const char *);
	Format & operator % (const std::string &);

	operator std::string () const;
};

SGU_NS_END

#endif
